/*	  Copyright (C) 2011  João Dias de Carvalho Neto

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package br.com.mysm.global
{
	import mx.core.UIComponent;
	
	/**
	 * Utilitary class to all the system
	 * 
	 * @author João Dias de Carvalho Neto 
	 */	
	public class Util extends UIComponent
	{		
		/**
		 *Default locale to be loaded into the project 
		 */
		public static var defaultLocale : String = "pt_BR";		
		
		
		private static function getMonth(value:int):String
		{
			value ++;
			
			if (value < 10)
			{
				return '0' + value;	
			}
			else
			{
				return value.toString();
			}
		}
		
		private static function getDay(value:int):String
		{
			if (value < 10)
			{
				return '0' + value;	
			}
			else
			{
				return value.toString();
			}
		}
		
		
		/**
		 * Convert a Date Object to Int in YYYYMMDD 
		 * @param date
		 * @return int
		 */		
		public static function convertDateToInt(date:Date):int
		{
			var rst : String;
			
			rst = date.fullYear.toString() + Util.getMonth(date.month)+
				Util.getDay(date.date);			
			return int(rst);
		}
		
		/**
		 * Convert a int in YYYYMMDD to a Date Object 
		 * @param date
		 * @return 
		 */		
		public static function convertIntToDate(date:int):Date
		{
			var year:Object = date.toString().substr(0,4);
			var month:Number = Number(date.toString().substr(4,2));
			var day:Number = Number(date.toString().substr(6,2));
			
			var d : Date = new Date(year,month-1,day);
			
			return d;
		}

	}	

}